home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / alib / csup / rexx_support / rexxvars.asm < prev    next >
Encoding:
Assembly Source File  |  1994-08-18  |  14.1 KB  |  428 lines

  1. * === rexxvars.asm =====================================================
  2. *
  3. * $Id: rexxvars.asm,v 30.8 1994/08/18 05:54:55 dice Exp dice $
  4. *
  5. * Copyright (c) 1988 William S. Hawes (All Rights Reserved)
  6. *
  7. * $Log: rexxvars.asm,v $
  8. ;; Revision 30.8  1994/08/18  05:54:55  dice
  9. ;; .
  10. ;;
  11. ;; Revision 30.0  1994/06/10  18:10:49  dice
  12. ;; .
  13. ;;
  14. ;; Revision 30.0  1994/06/10  18:10:49  dice
  15. ;; .
  16. ;;
  17. * Revision 36.1  90/08/28  10:03:12  mks
  18. * First "QUICK-FIX" of RexxVars.asm for the trashing of D2.
  19. * This is a correct fix but not most optimal.
  20. * Also, made to assemble on my system.
  21. * RexxVars.asm is now under RCS control
  22. * ======================================================================
  23. * Functions to implement the ARexx direct variable interface.
  24.  
  25.          INCLUDE  "rexx/storage.i"
  26.          INCLUDE  "rexx/rxslib.i"
  27.          INCLUDE  "rexx/errors.i"
  28.          INCLUDE  "rexx/rexx.i"
  29.  
  30. LINKSYS MACRO           ; link to a library without having to see a _LVO
  31.         MOVE.L  A6,-(SP)
  32.         MOVE.L  \2,A6
  33.         JSR     _LVO\1(A6)
  34.         MOVE.L  (SP)+,A6
  35.         ENDM
  36.  
  37. CALLSYS MACRO           ; call a library via A6 without having to see _LVO
  38.         JSR     _LVO\1(A6)
  39.         ENDM
  40.  
  41. XLIB    MACRO           ; define a library reference without the _LVO
  42.         XREF    _LVO\1
  43.         ENDM
  44. ;
  45.  
  46.          XREF     _AbsExecBase
  47.  
  48.          XDEF     CheckRexxMsg
  49.          XDEF     _CheckRexxMsg
  50.          XDEF     GetRexxVar
  51.          XDEF     _GetRexxVar
  52.          XDEF     SetRexxVar
  53.          XDEF     _SetRexxVar
  54.  
  55.          ; EXEC library routines
  56.  
  57.          XLIB     CloseLibrary
  58.          XLIB     OpenLibrary
  59.  
  60.          STRUCTURE StackFrame,0
  61.          APTR     sf_MsgPtr            ; message pointer
  62.          APTR     sf_Save1             ; 1st error trap
  63.          APTR     sf_Save2             ; 2nd error trap
  64.          LABEL    sf_SIZEOF            ; size: 12 bytes
  65.  
  66.  
  67. * Checks whether a message came from a valid REXX context.
  68. * Usage: boolean = CheckRexxMsg(rmptr);
  69. _CheckRexxMsg
  70.          move.l   4(sp),a0             ; message packet
  71.  
  72. * ========================     CheckRexxMsg     ========================
  73. * Verifies that the message represents a valid REXX context.
  74. * Registers:   A0 -- message
  75. * Return:      D0 -- boolean
  76. CheckRexxMsg
  77.          movem.l  d2/a2/a6,-(sp)
  78.          movea.l  a0,a2
  79.          movea.l  _AbsExecBase,a6      ; EXEC library base
  80.  
  81.          ; Open the REXX Systems library
  82.  
  83.          lea      RXSLib(pc),a1        ; library name
  84.          moveq    #0,d0                ; any version
  85.          CALLSYS  OpenLibrary
  86.          move.l   d0,d2                ; library opened?
  87.          beq.s    1$                   ; no??
  88.  
  89.          ; Close the library ...
  90.  
  91.          movea.l  d0,a1
  92.          CALLSYS  CloseLibrary
  93.  
  94.          ; Make sure the library matches the message LibBase pointer ...
  95.  
  96.          moveq    #0,d0                ; clear return
  97.          cmp.l    rm_LibBase(a2),d2    ; matches?
  98.          bne.s    1$                   ; no
  99.          move.l   rm_TaskBlock(a2),d1  ; global pointer?
  100.          beq.s    1$                   ; no
  101.  
  102.          ; Make sure the message came from REXX ...
  103.  
  104.          movea.l  a2,a0                ; message
  105.          movea.l  d2,a6                ; REXX base
  106.          CALLSYS  IsRexxMsg            ; D0=boolean
  107.  
  108. 1$:      tst.l    d0                   ; set CCR
  109.          movem.l  (sp)+,d2/a2/a6
  110.          rts
  111.  
  112. * Retrieves the value of a variable from the current storage environment.
  113. * USAGE: error = GetRexxVar(msgptr,name,&return);
  114. _GetRexxVar
  115.          movem.l  4(sp),a0/a1          ; message/variable name
  116.          bsr.s    GetRexxVar           ; D0=error A1=value
  117.          bne.s    1$                   ; ... error
  118.          movea.l  12(sp),a0            ; return pointer
  119.          move.l   a1,(a0)              ; install value
  120.  
  121. 1$:      rts
  122.  
  123. * =========================     GetRexxVar     =========================
  124. * Retrieves the value of a variable from the current storage environment.
  125. * Registers:   A0 -- context
  126. *              A1 -- variable name
  127. * Return:      D0 -- error code
  128. *              A1 -- value (argstring)
  129. GetRexxVar
  130.          movem.l  d2/d3/a2-a6,-(sp)
  131.          movea.l  a0,a2                ; save message
  132.          movea.l  a1,a3                ; save buffer
  133.  
  134.          ; Check for a valid context
  135.  
  136.          bsr      CheckRexxMsg         ; D0=boolean
  137.          beq.s    GRVErr10             ; invalid context
  138.          movea.l  rm_LibBase(a2),a6    ; REXX base
  139.  
  140.          ; Find the current storage environment
  141.  
  142.          movea.l  rm_TaskBlock(a2),a0  ; global pointer
  143.          CALLSYS  CurrentEnv           ; D0=A0=environment
  144.          movea.l  a0,a4                ; save it
  145.  
  146.          ; Create the stem and compound parts
  147.  
  148.          movea.l  a3,a0                ; name
  149.          bsr      TypeString           ; D0=error D1=compound A1=stem
  150.          bne.s    GRVOut               ; ... failure
  151.          movea.l  a1,a2                ; save stem
  152.          move.l   d1,d2                ; save compound
  153.  
  154.          ; Look up the value ...
  155.  
  156.          movea.l  a4,a0                ; environment
  157.          move.l   d2,d0                ; compound string
  158.          moveq    #0,d1                ; clear node
  159.          CALLSYS  FetchValue           ; D0=node  D1=flag  A1=value
  160.          moveq    #0,d0                ; all OK
  161.  
  162.          ; Check for a literal value (and return NULL)
  163.  
  164.          addq.l   #ns_Buff,a1          ; offset to string
  165.          tst.l    d1                   ; a literal?
  166.          beq.s    GRVOut               ; no
  167.          suba.l   a1,a1                ; clear pointer
  168.          bra.s    GRVOut
  169.  
  170.          ; Error conditions
  171.  
  172. GRVErr10 moveq    #10,d0               ; invalid context
  173.  
  174. GRVOut   tst.l    d0                   ; set CCR
  175.          movem.l  (sp)+,d2/d3/a2-a6
  176.          rts
  177.  
  178. * USAGE: error = SetRexxVar(message,name,value,length)
  179. _SetRexxVar
  180.          movem.l  4(sp),a0/a1
  181.          movem.l  12(sp),d0/d1
  182.  
  183. * =========================     SetRexxVar     =========================
  184. * Assigns a value to a variable in the current storage environment.
  185. * Registers:   A0 -- context
  186. *              A1 -- variable name
  187. *              D0 -- value
  188. *              D1 -- length
  189. * Return:      D0 -- error code
  190. STACKBF  SET      sf_SIZEOF
  191. SetRexxVar
  192.          movem.l  d2-d7/a2-a6,-(sp)
  193.          lea      -STACKBF(sp),sp      ; stack frame
  194.          movea.l  a0,a2                ; save message
  195.          movea.l  a1,a3                ; save name
  196.          movea.l  d0,a5                ; save value
  197.          move.l   d1,d3                ; save length
  198.  
  199.          ; Install our own error trap
  200.  
  201.          lea      SRVErr3(pc),a0       ; trap location
  202.          movea.l  sp,a1                ; stack frame
  203.          bsr      SaveTrap
  204.  
  205.          ; Check for a valid context
  206.  
  207.          movea.l  a2,a0                ; message packet
  208.          bsr      CheckRexxMsg         ; D0=boolean
  209.          beq.s    SRVErr10             ; invalid context
  210.          movea.l  rm_LibBase(a2),a6    ; REXX base
  211.  
  212.          ; Make sure the value string is not too long
  213.  
  214.          moveq    #9,d0                ; string too long
  215.          cmpi.l   #65535,d3            ; too long?
  216.          bgt.s    SRVOut               ; yes
  217.  
  218.          ; Find the current storage environment
  219.  
  220.          movea.l  rm_TaskBlock(a2),a0  ; global pointer
  221.          CALLSYS  CurrentEnv           ; D0=A0=environment
  222.          movea.l  a0,a4                ; save environment
  223.  
  224.          ; Create the stem and compound parts ...
  225.  
  226.          movea.l  a3,a0                ; variable name
  227.          bsr      TypeString           ; D0=error D1=compound A1=stem
  228.          bne.s    SRVOut               ; ... failure
  229.          movea.l  a1,a2                ; save stem
  230.          move.l   d1,d2                ; save compound
  231.  
  232.          ; Locate or create the symbol node ...
  233.  
  234.          movea.l  a4,a0                ; environment
  235.          move.l   d2,d0                ; compound string
  236.          CALLSYS  EnterSymbol          ; D0=A0=node A1=value
  237.          move.l   d0,d4                ; save node
  238.  
  239.          ; Create the value string ...
  240.  
  241.          movea.l  a4,a0                ; environment
  242.          movea.l  a5,a1                ; pointer
  243.          move.l   d3,d0                ; length
  244.          bsr      MakeString           ; D0=A0=string
  245.          beq.s    SRVErr3              ; ... failure
  246.  
  247.          ; Install the value string
  248.  
  249.          movea.l  a4,a0                ; environment
  250.          movea.l  d0,a1                ; value string
  251.          move.l   d4,d0                ; symbol table node
  252.          CALLSYS  SetValue             ; D0=node A1=value
  253.  
  254.          moveq    #0,d0
  255.          bra.s    SRVOut
  256.  
  257.          ; Error conditions
  258.  
  259. SRVErr3  moveq    #3,d0                ; allocation failure
  260.          bra.s    SRVOut
  261.  
  262. SRVErr10 moveq    #10,d0               ; invalid context
  263.  
  264. SRVOut   movea.l  sp,a0                ; stack level
  265.          move.l   d0,-(sp)             ; push error
  266.          bsr      RestoreTrap
  267.          move.l   (sp)+,d0             ; pop error
  268.  
  269.          lea      STACKBF(sp),sp
  270.          movem.l  (sp)+,d2-d7/a2-a6
  271.          rts
  272.  
  273. * =========================     TypeString     =========================
  274. * Classifies a symbol and returns the stem and compound parts.
  275. * Registers:   A0 -- variable name
  276. *              A4 -- environment
  277. * Return:      D0 -- error code
  278. *              D1 -- compound name
  279. *              A1 -- stem name
  280. TypeString
  281.          movem.l  d2/d3/a2/a3,-(sp)
  282.          moveq    #0,d2                ; clear error
  283.          moveq    #0,d3
  284.  
  285.          CALLSYS  Strlen               ; D0=length
  286.          movea.l  a0,a1
  287.          movea.l  a4,a0                ; environment
  288.          bsr.s    MakeString           ; D0=A0=string
  289.          movea.l  d0,a2                ; save string
  290.          beq.s    TSErr3               ; failure ...
  291.  
  292.          ; Now check whether it looks like a stem ...
  293.  
  294.          lea      ns_Buff(a2),a1       ; buffer area
  295.          move.w   ns_Length(a2),d0     ; length
  296.          move.l   a1,d1
  297.  
  298. 1$:      cmpi.b   #'.',(a1)+           ; a period?
  299.          dbeq     d0,1$                ; loop back
  300.          bne.s    2$                   ; not compound
  301.  
  302.          exg      d1,a1                ; begin=>A1 , end=>D1
  303.          sub.l    a1,d1                ; stem length
  304.          move.l   a2,d3                ; compound part
  305.  
  306.          ; Create the stem string ...
  307.  
  308.          movea.l  a4,a0                ; environment
  309.          move.l   d1,d0                ; length
  310.          bsr.s    MakeString           ; D0=A0=string
  311.          movea.l  d0,a2                ; save it
  312.          beq.s    TSErr3               ; failure
  313.  
  314.          ; Check for a valid stem ...
  315.  
  316. 2$:      lea      ns_Buff(a2),a0       ; string pointer
  317.          CALLSYS  IsSymbol             ; D0=code D1=length
  318.          cmp.w    ns_Length(a2),d1     ; full length?
  319.          beq.s    TSOut                ; yes
  320.  
  321.          moveq    #40,d2               ; variable expected
  322.          bra.s    TSOut
  323.  
  324. TSErr3   moveq    #3,d2                ; allocation failure
  325.  
  326. TSOut    tst.l    d2                   ; error?
  327.          beq.s    1$                   ; no ... all OK
  328.  
  329.          ; Release intermediate strings ...
  330.  
  331.          movea.l  a4,a0                ; environment
  332.          movea.l  a2,a1                ; stem part
  333.          bsr.s    FreeString           ; release it
  334.  
  335.          movea.l  a4,a0                ; environment
  336.          movea.l  d3,a1                ; compound part
  337.          bsr.s    FreeString           ; release it
  338.  
  339. 1$:      movea.l  a2,a1                ; stem return
  340.          move.l   d3,d1                ; compound return
  341.          move.l   d2,d0                ; set CCR
  342.          movem.l  (sp)+,d2/d3/a2/a3
  343.          rts
  344.  
  345. * =========================     MakeString     =========================
  346. * Allocates and initializes a string structure.
  347. * Registers:   A0 -- environment
  348. *              A1 -- string
  349. *              D0 -- length
  350. * Return:      D0 -- string structure
  351. *              A0 -- same
  352. MakeString
  353.          movem.l  d0/a1,-(sp)          ; push length/pointer
  354.          addq.l   #ns_Buff,d0          ; add offset
  355.          addq.l   #1,d0                ; plus null byte
  356.          CALLSYS  GetSpace             ; D0=A0=structure
  357.          movem.l  (sp)+,d0/a1          ; pop length/pointer
  358.          beq.s    1$                   ; failure ...
  359.  
  360.          move.l   a0,-(sp)             ; push pointer
  361.          clr.l    (a0)
  362.          move.w   d0,ns_Length(a0)
  363.          move.b   #NSF_STRING,ns_Flags(a0)
  364.          clr.b    ns_Buff(a0,d0.l)     ; null byte
  365.          addq.l   #ns_Buff,a0          ; offset to buffer
  366.          CALLSYS  StrcpyN              ; D0=hash
  367.          movea.l  (sp)+,a0             ; pop pointer
  368.          move.b   d0,ns_Hash(a0)       ; install hash byte
  369.  
  370. 1$:      move.l   a0,d0                ; set CCR
  371.          rts
  372.  
  373. * ========================     FreeString     ==========================
  374. * Releases a string structure, if it's not owned at the time.
  375. * Registers:   A0 -- environment
  376. *              A1 -- string structure
  377. FreeString
  378.          move.l   a1,d1
  379.          beq.s    1$
  380.          moveq    #NSF_KEEP,d0         ; ownership bits
  381.          and.b    ns_Flags(a1),d0      ; owned?
  382.          bne.s    1$                   ; yes
  383.  
  384.          move.w   ns_Length(a1),d0     ; string length
  385.          addq.l   #ns_Buff,d0          ; add offset
  386.          addq.l   #1,d0                ; plus null byte
  387.          CALLSYS  FreeSpace
  388.  
  389. 1$:      rts
  390.  
  391. * ==========================     SaveTrap     ==========================
  392. * Saves the global error code
  393. * Registers:   A0 -- trap location
  394. *              A1 -- stack level
  395. *              A2 -- message packet
  396. SaveTrap
  397.          move.l   a3,-(sp)
  398.          movea.l  rm_TaskBlock(a2),a3  ; global context
  399.  
  400.          move.l   a2,sf_MsgPtr(a1)
  401.          movem.l  rt_ErrTrap(a3),d0/d1 ; old trap
  402.          movem.l  a0/a1,rt_ErrTrap(a3) ; new trap
  403.          movem.l  d0/d1,sf_Save1(a1)   ; save old trap
  404.  
  405.          movea.l  (sp)+,a3
  406.          rts
  407.  
  408. * =========================     RestoreTrap     ========================
  409. * Restores the global error trap values for the REXX context.
  410. * Registers:   A0 -- stack frame
  411. RestoreTrap
  412.          movea.l  sf_MsgPtr(a0),a1
  413.          movea.l  rm_TaskBlock(a1),a1  ; global context
  414.  
  415.          movem.l  sf_Save1(a0),d0/d1   ; saved trap values
  416.          movem.l  d0/d1,rt_ErrTrap(a1) ; restore values
  417.          rts
  418.  
  419.          ; String data
  420.  
  421. RXSLib   RXSLIBNAME                    ; library name
  422.          CNOP     0,2
  423.  
  424.          END
  425.